package com.hwua.dao.Impl;

import com.hwua.Util.C3P0Util;
import com.hwua.dao.IOrderDao;
import com.hwua.entity.Order;
import com.hwua.entity.ProductCategory;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * @author: create by  Raphaelkxy
 * @version: v1.0
 * @description: com.hwua.dao.Impl
 * @date:2019/9/2
 */
public class OrderDaoImpl implements IOrderDao {

    private QueryRunner queryRunner=null;

    public OrderDaoImpl() {
        queryRunner=new QueryRunner(C3P0Util.getCpds());
    }
    @Override
    public List<Order> selectOrderByuid(int uid) throws SQLException {
        String sql="SELECT * from amz_order WHERE uid =?";
        Object[]args ={uid};
        return queryRunner.query(sql,new BeanListHandler<Order>(Order.class),args);
    }



    @Override
    public int insertOrder(Order order) throws SQLException {
       String sql="INSERT INTO amz_order VALUES (null,?, ?, ?, ?, ?, ?, ?)";
        Object[] args={order.getUid(),order.getUname(),order.getUaddress(),order.getCreatetime(),order.getMoney(),order.getStatus(),order.getType()};
        return queryRunner.update(sql,args);
    }



}
